package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Permission;
import cn.wolfcode.service.IPermissionService;
import cn.wolfcode.util.JsonResult;
import cn.wolfcode.util.QueryObject;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//权限控制器
@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;
    //查询    /permission/list.do
    @RequestMapping("/list")
    public String list(Model model , @ModelAttribute("qo")QueryObject qo){
        PageInfo<Permission> pageResult = permissionService.query(qo);
        model.addAttribute("pageResult",pageResult);
        return "permission/list";
    }
    //删除    /permission/delete.do?id=?
    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult delete(Long id){
        if (id != null) {
            permissionService.deleteById(id);
        }
        return new JsonResult();
    }

    // 加载
    @RequestMapping("/reload")
    @ResponseBody
    public JsonResult reload() {
        permissionService.reload();
        return new JsonResult();

    }
}
